const { readFile } = require('fs')
const EventEmitter = require('events')

// 声明 EE 继承 EventEmitter
class EE extends EventEmitter{}

const yy = new EE()

yy.on('event', () => {
	console.log('出大事了！')
})

setTimeout(() => {
	console.log('0 毫秒后到期执行的定时器回调')
}, 0)

setTimeout(() => {
	console.log('100 毫秒后到期执行的定时器回调')
}, 100)

setTimeout(() => {
	console.log('200 毫秒后到期执行的定时器回调')
}, 200)

readFile('../package.json', 'utf-8', data => {
	console.log('完成文件 1 读操作的回调')
})

readFile('../README.md', 'utf-8', data => {
	console.log('完成文件 2 读操作的回调')
})

setImmediate(() => {
	console.log('Immediate 立即回调')
})


process.nextTick(()=>{
	console.log('process.nextTick 立即回调')
})

Promise.resolve()
	.then(()=>{
		yy.emit('event')

		process.nextTick(()=>{
			console.log('process.nextTick 第二次回调')
		})

		console.log('Promise 第一次回调')
	})
	.then(()=>{
		console.log('Promise 第二次回调')
	})